package com.zyh.testtoolbar;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.support.design.widget.TabLayout;
import android.widget.LinearLayout;
import android.view.WindowManager;
//import android.support.design.widget.TabLayout;
//import android.widget.Table

public class MainActivity extends ActionBarActivity {

	private DrawerLayout mDrawerLayout;
	private ActionBarDrawerToggle mDrawerToggle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		StatusBarCompat.compat(this, getResources().getColor(R.color.material_deep_teal_500));
		setContentView(R.layout.activity_main);
//透明状态栏
			//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
			//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			
		// 设置ToolBar
		Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
		// Title
		toolbar.setTitle("Toolbar的标题");
		// App Logo
		 toolbar.setLogo(R.drawable.ic_launcher);
		// Sub Title
		toolbar.setSubtitle("Sub title");
  //  TabLayout layout = null;
		if (toolbar != null) {
			setSupportActionBar(toolbar);
		}

		// Navigation Icon 要0定在 setSupoortActionBar 才有作用
		// 否00出0 back button
		toolbar.setNavigationIcon(R.drawable.perm_group_system_tools);

		// 打0 up button
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
		// 0作 drawer toggle 0放入 toolbar
		mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open,
				R.string.drawer_close);
		mDrawerToggle.syncState();
		mDrawerLayout.setDrawerListener(mDrawerToggle);
		
			//int statusBarHeight = getStatusBarHeight();
		//	toolbar.setPadding(0, statusBarHeight, 0, 0);
		//TabLayout layout=new TabLayout(this);
		//LinearLayout linearlayout = (LinearLayout)findViewById(R.id.drawer_view);
		//linearlayout.addView(layout);
	}
	
	  /**
     * 用于获取状态栏的高度。 使用Resource对象获取（推荐这种方式）
     *
     * @return 返回状态栏高度的像素值。
     */
    public int getStatusBarHeight()
		{
			int result = 0; 
			int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
			if (resourceId > 0)
				{
					result = getResources().getDimensionPixelSize(resourceId);
				}
			return result; 
			}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
			if (id == android.R.id.home)
		{
					onBackPressed();
					return true;
				}
		return super.onOptionsItemSelected(item);
	}
}
